//判断对象是否为空
function isNull(obj) {
	return (obj == null || obj == undefined);
}

//判断对象是否为空，如果对象是字符串，判断字符串是否为空字符串，或者是否只包含空格
function isNullOrEmpty(obj) {
	if (isNull(obj))
		return true;
    if (typeof(obj) == "string") {
        if (obj == "")
        	return true;
    	var trimStr = obj.replace(/(^\s*)|(\s*$)/g, "");
    	return (trimStr == "");
    }
    return false;
}

function isNumber(obj) {
	if (isNull(obj))
		return false;
	return (typeof(obj) == "number");
}

//获取对象的数值，如果对象转换数值失败，返回缺省值
function getNumber(obj, defaultValue) {
	var num = parseInt(obj);
	if (isNaN(num))
		num = defaultValue;
	return num;
}

//去除字符串的前后空格
function trimString(str) {
	if (str == null || str == undefined || str == "") {
		return null;
	}
	var trimStr = str.replace(/(^\s*)|(\s*$)/g, "");
	return (trimStr == "") ? null : trimStr;
}

//加入收藏            
function addFavorite(title, url) {
	if (url == null)
		url = window.location.href;
	url = encodeURI(url);
    try {
        window.external.addFavorite(url, title);
    } catch (e) {
        try {
            window.sidebar.addPanel(title, url, "");
        } catch (e) {
            alert("加入收藏失败，请使用Ctrl+D进行添加,或手动在浏览器里进行设置.");
        }
    }
}

/*function addFavoriteOfPlat(title,req_url){
	if (req_url == null)
		req_url = window.location.href;
	var url = encodeURI(getReqUrlPrefix(req_url,getUri(req_url))+getRepUri(getUri(req_url)));
    try {
        window.external.addFavorite(url, title);
    } catch (e) {
        try {
            window.sidebar.addPanel(title, url, "");
        } catch (e) {
            alert("加入收藏失败，请使用Ctrl+D进行添加,或手动在浏览器里进行设置.");
        }
    }
	
}
//获取uri前缀
function getReqUrlPrefix(url,uri){
	var req_url = url;
	if(url.indexOf(uri)>=0){
		req_url = req_url.substring(0,req_url.indexOf(uri));
	}
	console.log("getReqUrlPrefix:"+req_url);
	return req_url;
}
function getUri(url){
	var uri;
	if(url.indexOf("c_huihaiLogin.do")>=0){
		uri = "c_huihaiLogin.do";
	}else if(url.indexOf("c_managerIndex.do")>=0){
		uri = "c_managerIndex.do";
	}else if(url.indexOf("c_enter.do")>=0){
		uri = "c_enter.do";
	}else{
		uri = "";
	}
	console.log("getUri:"+uri);
	return uri;
}
//返回登录后页对应的uri
function getRepUri(uri){
	var rep_uri;
	switch (uri) {
	case "c_huihaiLogin.do":
		rep_uri = "hhkj.jsp";
		break;
	case "c_managerIndex.do":
		rep_uri = "c_managerLogin.do";
		break;
	case "c_enter.do":
		rep_uri = "";
		break;	
	default:
		rep_uri = "";
		break;
	}
	console.log("getRepUri:"+rep_uri);
	return rep_uri;
}*/
//设为首页
function setHomePage(url) {
    if (document.all) {
        document.body.style.behavior = 'url(#default#homepage)';
        document.body.setHomePage(url);
    } else {
        alert("您好,您的浏览器不支持自动设置页面为首页功能,请您手动在浏览器里设置该页面为首页!");
    }
}

//获取变化参数
function getVariableParam() {
	//获取时间字符串
	return (new Date()).valueOf();
	//获取随机字符串
	//return (Math.random() + "").substr(2);	
}

//获取新的变化URL，tag为最后一个参数名称
function newVariableParam(url, tag) {
	if (url == null)
		return url;
	tag = tag + "=";
	var idx = url.indexOf(tag);
	if (idx <= 0)
		return url;
	url = url.substr(0, idx);
	return url + tag + getVariableParam();
}

//获取URL参数值
function getQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	//var reg = new RegExp("(^|&)" + name + "=(.*[\}])($)", "i");
	var r = window.location.search.substr(1).match(reg);
	return (r == null) ? null : unescape(r[2]);
}

function getQueryStringEx(name) {
	var reg = new RegExp("(^|&)" + name + "=(.*[\}])($)", "i");
	var r = window.location.search.substr(1).match(reg);
	return (r == null) ? null : unescape(r[2]);
}

function getQueryStringRegExp(name) {
	var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i");
	if (reg.test(location.href)) {
		return unescape(RegExp.$2.replace(/\+/g, " "));
	} else {
		return null;
	}
}

//post方式frame传参
function setFrame(frameObj) {
	if (!frameObj.name || frameObj.name == "")
		frameObj.name = frameObj.id;
}

//创建临时传参form
function createForm(data) {
	var newForm = document.createElement("form");
	newForm.id = "forPostForm";
	newForm.method = "post";
	newForm.action = data.url;
	newForm.target = data.target.name;
	var paramObj, params = data.params;
	for (var paramName in params) {
		paramObj = document.createElement("input");
		paramObj.type = "hidden";
		paramObj.name = paramName;
		paramObj.value = params[paramName];
		newForm.appendChild(paramObj);
	}
	return newForm;
}

//删除临时传参form
function deleteForm() {
	var oldForm = document.getElementById("forPostForm");
	if (oldForm) {
		document.body.removeChild(oldForm);
	}
}

/**
 * 给嵌套的iframe界面Post值
 * 参数：
 * data - 传递对象
 * { url - frame页面url, target - iframe对象, params - post参数, { 参数名1 : 值1, 参数名2 : 值2 } }
 * 例如：{ url: "page.jsp", target: frameObj, params: { "arg1": "1", "arg2": "2" } }
 */
function doPostToFrame(data) {
	setFrame(data.target);
	deleteForm();
	var newForm = createForm(data);
	document.body.appendChild(newForm);
	newForm.submit();
	deleteForm();
}

//PNG图片透明处理
function correctPNG() { // correctly handle PNG transparency in Win IE 5.5 & 6. 
    var arVersion = navigator.appVersion.split("MSIE");
    var version = parseFloat(arVersion[1]);
    if ((version >= 5.5) && (document.body.filters)) {
        for (var j = 0; j < document.images.length; j++) {
            var img = document.images[j];
            var imgName = img.src.toUpperCase();
            if (imgName.substring(imgName.length - 3, imgName.length) != "PNG")
            	continue;
            var imgID = (img.id) ? "id='" + img.id + "' " : "";
            var imgClass = (img.className) ? "class='" + img.className + "' " : "";
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
            var imgStyle = "display:inline-block;" + img.style.cssText;
            if (img.align == "left")
            	imgStyle = "float:left;" + imgStyle;
            if (img.align == "right")
            	imgStyle = "float:right;" + imgStyle;
            if (img.parentElement.href)
            	imgStyle = "cursor:hand;" + imgStyle;
            var strNewHTML = "<span " + imgID + imgClass + imgTitle +
            	" style=\"" + "width:" + img.width + "px; height:" + 
            	img.height + "px;" + imgStyle + ";" +
            	"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + 
            	"(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
           	img.outerHTML = strNewHTML;
            j = j - 1;
        }
    }
}

//处理时间格式
Date.prototype.format = function(format){
	var o = {
		"M+" : this.getMonth()+1, //month
		"d+" : this.getDate(), //day
		"h+" : this.getHours(), //hour
		"m+" : this.getMinutes(), //minute
		"s+" : this.getSeconds(), //second
		"q+" : Math.floor((this.getMonth()+3)/3), //quarter
		"S" : this.getMilliseconds() //millisecond
	};

	if(/(y+)/.test(format)) {
		format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
	}

	for(var k in o) {
		if(new RegExp("("+ k +")").test(format)) {
			format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
		}
	}
	return format;
};

// 判断IE浏览器是否安装了Flash
function flashIsValidForIE() {
    var swf = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
    return (swf != null);
}

// 判断Firefox、Chrome等浏览器是否安装了Flash
function flashIsValidFireFox() {
    var flashMode = 0;
    if (navigator.plugins && navigator.plugins.length > 0) {
        if (navigator.plugins["Shockwave Flash"]) {
            var plugin_version = 0;
            var words = navigator.plugins["Shockwave Flash"].description.split(" ");
            for (var i = 0; i < words.length; ++i) {
                if (isNaN(parseInt(words[i])))
                    continue;
                plugin_version = words[i];
            }
            if (plugin_version >= 5) {
                var plugin = navigator.plugins["Shockwave Flash"];
                var numTypes = plugin.length;
                for (var j = 0; j < numTypes; j++) {
                    mimetype = plugin[j];
                    if (mimetype) {
                        if (mimetype.enabledPlugin && (mimetype.suffixes.indexOf("swf") != -1))
                            flashMode = 1;
                        // Mac wierdness
                        if (navigator.mimeTypes["application/x-shockwave-flash"] == null)
                            flashMode = 0;
                    }
                }
            }
        }
    }
    return (flashMode == 1);
}

// 判断浏览器是否安装了Flash
function flashIsValid() {
    //alert(navigator.userAgent);
    if (navigator.userAgent &&
        navigator.userAgent.indexOf("MSIE") >= 0 &&
        navigator.appVersion.indexOf("Win") >= 0) {
        return flashIsValidForIE();
    } else {
        return flashIsValidFireFox();
    }
}
//传递对象：schType=学校类型，sidUrl=获取子系统sessionId路径，sysSid=子系统sessionId,orgId=单位id
function getSysBySchType(obj){
	//if(schType==2)return;
	var sys = new Array(2);
	
	//子系统前缀
	sysUrl = sy_getRight("c_getSysUrl.do?schType="+obj["schType"]);
	var v_url = sy_getRight("c_visitSys.do?un=" +getVariableParam()+"&schType="+obj["schType"]);
	if(v_url.indexOf("c_redirectHtml1.do") != -1){
		 syn_visitJsp({sidUrl:v_url,sysSid:sysSid,schType:obj["schType"],orgId:obj["orgId"]});
	}else{
		sysSid = v_url;
		jsonpCallBack({sidUrl:v_url,sysSid:sysSid,schType:obj["schType"],orgId:obj["orgId"]});
	}
	
}

function syn_visitJsp(obj) {
	$.ajax({
		url : obj["sidUrl"],
		type : "get",
		dataType : "jsonp",
		jsonp:"callbackparam",
		 jsonpCallback: "success_jsonpCallback",
		async : false,
		success : function(data) {
		
				jsonpCallBack({sidUrl:obj["sidUrl"],sysSid:data.sid,schType:obj["schType"],orgId:obj["orgId"]});
			},
			error:function(){
				alert("系统内部错误");
			}
		});
	}
function refreshSession(){
	$.ajax({
		url : "c_refreshSession.do",
		type : "get",
		dataType : "json",
		async : false,
		success : function(data) {
		}
		});
}
window.setInterval(refreshSession,600000);


